﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ManiaSongs.model;

namespace ManiaSongs
{
    public partial class ManiaSys : Form
    {
        public ManiaSys()
        {
            InitializeComponent();

          //  Init();
        }

      
        private IList<ManiaSongs.model.SongInfo> _files;

        public IList<SongInfo> Files
        {
            get
            {
                if (_files == null)
                {
                    if (string.IsNullOrEmpty(txeDirName.Text))
                    {
                        return null;
                    }
                    _files = dal.SongDal.GetAllInfoFromDir(txeDirName.Text);
                }
                return _files;
            }
            set { _files = value; }
        }

        private void Init()
        {
            this.gridControl1.DataSource = Files;
            this.gridControl1.RefreshDataSource();
        }

        //打开文件夹
        private void BtnOpenDir_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog open = new FolderBrowserDialog();
            if (open.ShowDialog() == DialogResult.OK)
            {
                 txeDirName.Text = open.SelectedPath;
                 Init();
            }
        }

        //删除按钮，需要1，删除rom 2，重新绑定数据
        private void btnDoDel_Click(object sender, EventArgs e)
        {
            var shouldDels = gridView1.GetSelectedRows();
            foreach (int index in shouldDels)
            {
                var info = Files[index];
                bll.SongBll.SafeDelete(info);
            }
            //清空之后 重新获取数据 绑定
            _files = null;
            Init();
        }

        private void btnBindData_Click(object sender, EventArgs e)
        {
            _files = null;
            Init();
        }
        
    }
}
